package com.umbrella.manage.config;

import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Configuration;

import com.umbrella.manage.cache.CacheKey;

/**
 *
 *
 * @author Wan, ChuanLong @ 08/08/2018
 */

@Configuration
public class UmCacheConfig extends CachingConfigurerSupport {
	
	public final static String _CACHE_NAME = "umbrellaPlateform";
    
	@Override
	public KeyGenerator keyGenerator() {
		return new org.springframework.cache.interceptor.KeyGenerator() {
			@Override
			public Object generate(Object o, java.lang.reflect.Method method, Object... objects) {
				
				StringBuilder sb = new StringBuilder();
//				sb.append(o.getClass().getName()).append(".");
				sb.append(method.getName());
				for (Object obj : objects) {
					
					sb.append(CacheKey._SEPARATOR);
					if(obj != null) {
						sb.append(obj.toString());						
					}
				}

				System.out.println("cacheKey:" + sb.toString());
				return sb.toString();
			}
		};
	}
}
